PROJECT(bundle_adjustment)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)

SET(TARGET_EXEC "bundle_adjuster")
SET(TARGET_SCRIPTS "camera_calibration")

SET(BA_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src")
SET(SCRIPTS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/scripts")

SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

FIND_PACKAGE(Ceres REQUIRED)
MESSAGE(STATUS "Found ceres-solver library version ${CERES_VERSION}")
INCLUDE_DIRECTORIES(${CERES_INCLUDE_DIRS})

SET(glog_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake-external/")
FIND_PACKAGE(glog REQUIRED PATHS cmake_external)
INCLUDE_DIRECTORIES(${GLOG_INCLUDE_DIRS})

SET(gflags_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake-external/")
FIND_PACKAGE(gflags REQUIRED PATHS cmake_external)
INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE_DIRS})

SET(SETTINGS "-std=c++14 -fopenmp -fexceptions -fpic")
SET(OPTIMIZATIONS "-D_FORTIFY_SOURCE=2 -march=native -mtune=native -ffast-math")
SET(DIAGNOSTICS "-Wall -Wextra -pedantic -Werror")


SET(BUILD_FLAGS "${SETTINGS} ${OPTIMIZATIONS} ${DIAGNOSTICS}")

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  #dirty hacky workaround
  ADD_DEFINITIONS( -D__extern_always_inline=inline )
  if(UNIX)
    if(CMAKE_GENERATOR STREQUAL "Ninja")
      LIST(APPEND CMAKE_C_FLAGS "-fcolor-diagnostics")
      LIST(APPEND CMAKE_CXX_FLAGS "-fcolor-diagnostics")
    endif(CMAKE_GENERATOR STREQUAL "Ninja")
  endif(UNIX)
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")

ADD_SUBDIRECTORY(${BA_PATH})
ADD_SUBDIRECTORY(${SCRIPTS_PATH})
